<template>
	<view class="tabBar_container">
		<view class="tabBar">
			<view class="bar" v-for="item in list" :key="item.index" @click.stop="nav(item)">
				<image class="icon" :src="selected == item.index ? item.selectBackground : item.background"></image>
				<text class="label"
					:style="{color : selected == item.index ? '#3c9cff' : '#d9d9d9'}">{{ item.label }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "CustomTabBar",
		data() {
			return {
				list: [
					// {
					// 	index: 0,
					// 	label: '主页',
					// 	url: '/pages/index/index',
					// 	background: '/static/tabbar/home.png',
					// 	selectBackground: '/static/tabbar/home_active.png',
					// },
					{
						index: 1,
						label: '商城',
						url: '/pages/shop/shop',
						background: '/static/tabbar/shop.png',
						selectBackground: '/static/tabbar/shop_active.png'
					},
					// {
					// 	index: 2,
					// 	label: '功能',
					// 	url: '/pages/function/function',
					// 	background: '/static/tabbar/function.png',
					// 	selectBackground: '/static/tabbar/function_active.png',
					// },
					{
						index: 3,
						label: '我的',
						url: '/pages/my/index',
						background: '/static/tabbar/my.png',
						selectBackground: '/static/tabbar/my_active.png',
					},
				],
			};
		},

		methods: {
			nav(item) {
				this.switchTab(item.url);
			},
			switchTab(url) {
				uni.switchTab({
					url,
					fail: (err) => {
						console.log(err);
					}
				})
			}
		},

		props: {
			selected: Number
		},
	}
</script>

<style lang="scss">
	.tabBar_container {
		width: 100%;
		height: 100rpx;
		position: fixed;
		display: flex;
		align-items: center;
		justify-content: center;

		bottom: 0;
		box-shadow: 0px 0px 13px 0px rgba(151, 151, 151, 0.22);
		border-radius: 28px 28px 0 0;

		background: #fff;

		// padding-bottom: calc(24rpx + constant(safe-area-inset-bottom));
		// padding-bottom: env(safe-area-inset-bottom);
		padding-bottom: 36rpx;

		z-index: 100;
	}

	.tabBar {
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		width: 100%;
		height: 100rpx;

		// padding: 10px 0 10px 0;

		background: #fff;
		border-radius: 28px 28px 0 0;

		.bar {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			margin-top: 10px;
			padding-left: 10px;
			padding-right: 10px;

			.label {
				font-size: 24rpx;
				font-weight: 500;
				line-height: 32rpx;
			}
		}
	}

	.icon {
		width: 24px;
		height: 24px;
	}
</style>